package cn.wetcland.urban.admin.service.impl;

import cn.wetcland.urban.admin.dto.AddressUpdateDTO;
import cn.wetcland.urban.admin.mapper.UtCustomerAddressMapper;
import cn.wetcland.urban.admin.service.UtCustomerAddressService;
import cn.wetcland.urban.common.MyAssert;
import cn.wetcland.urban.common.utils.CopyObjectUtil;
import cn.wetcland.urban.generator.domain.UtCustomerAddress;
import cn.wetcland.urban.generator.dto.BaseConditionSearchDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* @author hongyao.tan
* @description 针对表【ut_customer_address】的数据库操作Service实现
* @createDate 2024-03-07 17:17:41
*/
@Service
public class UtCustomerAddressServiceImpl extends ServiceImpl<UtCustomerAddressMapper, UtCustomerAddress> implements UtCustomerAddressService {

    @Resource
    private UtCustomerAddressMapper customerAddressMapper;

    @Override
    public Page<UtCustomerAddress> addressList(BaseConditionSearchDTO searchDTO) {
        Page<UtCustomerAddress> utCustomerAddressPage = new Page<>(searchDTO.getCurPage(), searchDTO.getPageSize());
        return customerAddressMapper.selectCustomerAddressPageList(utCustomerAddressPage, searchDTO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addressUpdate(AddressUpdateDTO updateDTO) {
        UtCustomerAddress utCustomerAddress = customerAddressMapper.selectById(updateDTO.getCustomerAddressId());
        MyAssert.notNull(utCustomerAddress, "地址不存在");
        utCustomerAddress.setAddressDetails(updateDTO.getAddressDetails());
        utCustomerAddress.setName(updateDTO.getName());
        utCustomerAddress.setPhone(updateDTO.getPhone());
        customerAddressMapper.updateById(utCustomerAddress);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addressDelete(Long addressId) {
        customerAddressMapper.deleteById(addressId);
    }
}




